$(function ()
{
    //findAll();
    page();
});

// window.onload = function ()
// {
//     findAll();
// };

function findAll()
{
    let msg = {};
    let pageModel = {};

    msg.username = $.trim($("#name").val());
    msg.startBirthday = $("#startBirthday").val();
    msg.endBirthday = $("#endBirthday").val();
    msg.introduce = $.trim($("#introduce").val());
    msg.sex = $("#sex").find("option:selected").text();
    msg.phone = $.trim($("#phone").val());
    msg.order = $.trim($("#order").val());
    msg.lift = $.trim($("#lift").val());

    pageModel.pageSize = $.trim($("#pageSize").val());
    pageModel.pageNum = $.trim($("#pageNum").val());
    pageModel.nowNum = $.trim($("#nowNum").val());
    msg.pageModel = pageModel;

    console.log(msg);

    let data = publivAjax('/back/user/findAll', msg, 'post');

    let html = '';
    $("#count").html(data.count);
    let list = data.list;
    if (list != null)
    {
        for (let i = 0; i < list.length; i++)
        {
            html += '<tr>\n' +
                '                <td>' + list[i].id + '</td>\n' +
                '                <td>' + list[i].username + '</td>\n' +
                '                <td>' + list[i].birthday + '</td>\n' +
                '                <td>' + list[i].introduce + '</td>\n' +
                '                <td>' + list[i].sex + '</td>\n' +
                '                <td>' + list[i].phone + '</td>\n' +
                '                <td>' + list[i].createTime + '</td>\n' +
                '                <td>' + list[i].updateTime + '</td>\n' +
                '                <td>\n' +
                '                    <div><a href="javascript:edit(' + list[i].id + ')">编辑</a></div>\n' +
                '                    <div><a href="javascript:del(' + list[i].id + ')">删除</a></div>\n' +
                '                </td>\n' +
                '            </tr>';
        }
    }

    $("#userFindAll").html(html);

}

function edit(id)
{
    // localStorage.setItem("userid", id);
    sessionStorage.setItem("userid", id);
    $('#b-right').load('/back/user/edit.html')
}

function del(id)
{
    let data = publivAjax('/back/user/del', {id: id}, 'post');

    if (data.result == 1)
    {
        findAll();
    }
}

function aihao()
{
    let hb = [];
    $("input:checkbox[name='hobby']").each(function ()
    {
        // console.log();
        if ($(this).prop("checked"))
        {
            hb.push($(this).val());
        }
    });

    return hb;
}